﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using MvcBlog.Common.Models;
using MvcBlog.Models;

namespace MvcBlog.ViewModels
{
    [PropertiesMustMatch("Password", "ConfirmPassword", ErrorMessage = "Sie müssen zweimal das gleiche Passwort eingeben.")]
    public class RegisterViewModel
    {

        public RegisterViewModel()
        {
        }

        public RegisterViewModel(User user)
        {

            this.Activated = user.Activated;
            this.RegistrationHash = user.RegistrationHash;
            this.Email = user.Email;
            this.Firstname = user.Firstname;
            this.Lastname = user.Lastname;
            this.Password = user.Password;
            this.UserName = user.Username;
            this.User_Id = user.User_ID;
        }

        [Required]
        [DisplayName("Vorname")]
        public string Firstname { get; set; }

        [Required]
        [DisplayName("Nachname")]
        public string Lastname { get; set; }

        [DisplayName("E-Mail")]
        public string Email { get; set; }

        [Required]
        [DisplayName("Benutzername")]
        public string UserName { get; set; }

        public int User_Id { get; set; }

        [Required]
        [StringLength(50, MinimumLength = 8, ErrorMessage = "Das Passwort muss mindestens 8 Zeichen lang sein.")]
        [DisplayName("Passwort")]
        public string Password { get; set; }

        [Required]
        [DisplayName("Passwort wiederholen")]
        public string ConfirmPassword { get; set; }

        public string RegistrationHash { get; set; }

        public bool Activated { get; set; }

        public void ApplyChanges(User u)
        {
            u.Firstname = this.Firstname;
            u.Lastname = this.Lastname;
            u.Password = this.Password;
            u.Username = this.UserName;
            u.Email = this.Email;
        }
    }
}